lorenzoquintimd
lorenzoquintimd
Lorenzo Quint I/M/D
42 posts
A blog to show process on certain subjects like Electronics 
Don't wanna be here? Send us removal request.
lorenzoquintimd · 6 years ago
Text
TEAM: CONSTRUCTION/MATERIALS MEMBERS: MELISA, HUNG RAE, LORENZO, ISABELLE.
1. Solar panel installation - Description of your installation: 
It is crucial to know how much sunlight we get per season thus installing a solar panel that relays the data to us is very useful knowledge. It allows us to consider planting what and where. - 
Block diagram of your installation
Tumblr media
Sketches
Tumblr media Tumblr media Tumblr media
NodeMCU Code
Tumblr media
NodeMCU + Thingspeak
Tumblr media Tumblr media Tumblr media
ANEMOMETER - Description of your installation: 
The Netherlands is super windy so we wanted to measure the amount of wind that passes through the garden. It allows us to consider planting what and where because some plants might be very sensitive to this. The potential wind energy could be used to power certain things in the garden in the future for example lights Block Diagram 
Tumblr media
Sketches 
Tumblr media
NodeMCU
Tumblr media
Nodemcu + Thingspeak
Tumblr media Tumblr media Tumblr media
0 notes
lorenzoquintimd · 6 years ago
Text
Project ScoopermanSunsave  MATERIAL X CONSTRUCTION
Tumblr media Tumblr media Tumblr media
PRESENTATION https://docs.google.com/presentation/d/1Hxp5nFNI3SUNkh2cxhGu-Zz9ZPBACDHkoO-zrw9DZWY/edit#slide=id.g548931b84e_0_8 
Tumblr media Tumblr media Tumblr media Tumblr media Tumblr media Tumblr media Tumblr media Tumblr media Tumblr media Tumblr media Tumblr media Tumblr media Tumblr media
0 notes
lorenzoquintimd · 6 years ago
Text
Tumblr media
Assignment 5: Check the WiFi network in the garden, especially in the area where you are planning to use the WiFi module.
To do so you can use a NodeMCU and send a "check number" to any of your channel on thingspeak.
Sketch the map of the garden and mark on the map the point that you check, use a red dot if there is not network and a green dot if there is network.
Tumblr media
There is a stable network
0 notes
lorenzoquintimd · 6 years ago
Text
Assignment 6: NODEMCU UPLINK: I AM PERSON A
“Create a channel in ThingSpeak and call it “KABK_ex2”. Connect one of the sensor we used in class to nodeMCU, read the sensor and send the measurement to your channel “KABK_ex2”, in file 1. Document the exercise: description, schematic, code and video “
I was uploading the information and Alexia was downloading it. 
Description
Uploading the temperature through DHT11-sensor and NodeMCU.  Collected the information of temperature sensor 
IMAGE____________________________________________________
Tumblr media
CODE______________________________________________________
#include <ESP8266WiFi.h> //Including library to use esp8266 #include <DHT.h>  // Including library for dht #include "ThingSpeak.h"   //Including library to send data to thingspeak #define DHTPIN 5          //pin where the dht11 is connected can use int as well define is constant DHT dht(DHTPIN, DHT11);   //create an object dht, define pin and model
//WiFi credentials char ssid[] = "KABK-Students";   // your network SSID (name) char pass[] = "kabk@air";   // your network password
WiFiClient  client;
//ThingSpeak credentials credentials unsigned long myChannelNumber = 778182; //your channel ID char myWriteAPIKey[] = "JGEOO0VKX0OK9OS2"; //"Write API" of your channel
//float data = 345;  //data that I sendf to thingspeak int wait = 20000; // Time between two uplinks float temp = 0;   //variable where to save temperture float hum = 0;    //variable where to save humidity
int wait2 = 1000;
void setup() {
 Serial.begin(9600);
 WiFi.begin(ssid, pass);
 Serial.print("Connecting");
 while (WiFi.status() != WL_CONNECTED)    {      delay(500);      Serial.print(".");      }
   Serial.println();    Serial.println("\nConnected.");
 dht.begin();          //Initialize DHT
 ThingSpeak.begin(client);  //Initialize ThingSpeak
}
void loop() {
    temp = dht.readTemperature();  //save the temperature in the variable temp     hum = dht.readHumidity();      //save the humidity in the variable hum
    Serial.print("Temperature: "); Serial.print(temp); Serial.println(" °C"); //print on serial temperature     Serial.print("Humidity: "); Serial.print(hum); Serial.println(" %");      //print on serial humidity     Serial.println("");
 // set the ThingSpeak fields with the values  ThingSpeak.setField(2, hum);
 // set the ThingSpeak fields with the values  ThingSpeak.setField(1, temp);
 // send uplink  ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
 // wait before the next measurment  delay(wait);
}
SCHEMATIC___________________________________________________
Tumblr media
IMAGES_________________________________________________________
Tumblr media Tumblr media
0 notes
lorenzoquintimd · 6 years ago
Text
Assignment 4: what is the difference between the variable types: ‘int’ and 'long’ in Arduino language? Write the answer in your blog
Integers according to Arduino: 
“Integers are your primary data-type for number storage.
On the Arduino Uno (and other ATmega based boards) an int stores a 16-bit (2-byte) value. This yields a range of -32,768 to 32,767 (minimum value of -2^15 and a maximum value of (2^15) - 1). On the Arduino Due and SAMD based boards (like MKR1000 and Zero), an int stores a 32-bit (4-byte) value. This yields a range of -2,147,483,648 to 2,147,483,647 (minimum value of -2^31 and a maximum value of (2^31) - 1).
int’s store negative numbers with a technique called (2’s complement math). The highest bit, sometimes referred to as the "sign" bit, flags the number as a negative number. The rest of the bits are inverted and 1 is added.
The Arduino takes care of dealing with negative numbers for you, so that arithmetic operations work transparently in the expected manner. There can be an unexpected complication in dealing with the bitshift right operator (>>) however.”  Long according to Arduino:  “Long variables are extended size variables for number storage, and store 32 bits (4 bytes), from -2,147,483,648 to 2,147,483,647.If doing math with integers, at least one of the numbers must be followed by an L, forcing it to be a long. See the Integer Constants page for details.” So Long can store 32 bits ( 4 bytes ) and Int can store 16 bits ( 2 bytes ). 
0 notes
lorenzoquintimd · 6 years ago
Text
EXTRA: Use one of the circuit of the previous exercise and send to your thing speak account the information of when the output device is on/off
Tumblr media
We wanted to send the on/off mode to the ThingSpeak server and we wanted to connect a relay to the highpower led: 
This was our code: 
#include <ESP8266WiFi.h>
#include "ThingSpeak.h"
const int led_pin = 5;  // LED in series with 470 ohm resistor on pin 10
float light = 0;
char ssid[] ="newlucht-students"; // this could be YOUR wifi here! char pass[] ="kabk@air"; // password
WiFiClient client; //thingspeak credential unsigned long myChannelNumber = 741403; // define channel nr char myWriteAPIKey[] = "1AHO0V2CFEX804GK"; // define api key of thingspeak
void setup() { Serial.begin(9600); pinMode(led_pin, OUTPUT);  WiFi.begin(ssid, pass);
 Serial.print("Connecting");
  while (WiFi.status() != WL_CONNECTED)  {    delay(500);    Serial.print(".");  }  Serial.println();  Serial.print("Connected.");
 ThingSpeak.begin(client); // initialize ThingSpeak }
void loop() {
 light = led_pin;    ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
 // incremental steps    analogWrite(led_pin, INPUT);    delay(5000);    analogWrite(led_pin, OUTPUT);    delay(5000); Serial.print("LIGHT:"); Serial.print(light); Serial.println("ON"); Serial.println(""); }
Photo of the circuit: 
Tumblr media
0 notes
lorenzoquintimd · 6 years ago
Video
tumblr
Assignment 3: Control the dc motor using the relay. Using digital write command. Use the same circuit and code to control the High Power Led.
//DESCRIPTION
It didn’t work because there was a problem with transistor and the dc motor. It was a general issue which we couldn’t 
//SKETCH
Tumblr media
//CODE
const int dc_pin = 8;  
void setup() { Serial.begin(9600); pinMode(dc_pin, OUTPUT);
}
void loop() {  // incremental steps
   digitalWrite(dc_pin, HIGH);    delay(8000);
   digitalWrite(dc_pin, LOW);    delay(8000);
   digitalWrite(dc_pin, HIGH);    delay(8000);
}
0 notes
lorenzoquintimd · 6 years ago
Text
Assignment 2: Control the High Power led with the MOSFET N-channel. Fade the light of the led using “analogWrite” command and “for” loop. Use the same circuit and code to control the motor.
Tumblr media
/// CODE
const int led_pin = 5; // define pin for led 
void setup() {  Serial.begin(9600);   // open the serial communication with the computer  pinMode(led_pin, OUTPUT);
}
void loop() {  for (int i = 0; i<= 255; i = i + 1){  // incremental steps    analogWrite(led_pin, i);    delay(10);  }
      for (int i = 255; i>= 0; i = i - 1){ // decremental steps    analogWrite(led_pin, i);    delay(10);  }
} VIDEO:https://drive.google.com/open?id=1s6Q0QDMdoZXx3U4WBChP43e-l3thJp4L
0 notes
lorenzoquintimd · 6 years ago
Text
UPDATED First assignment of the new semester // DHT11 + NodeMCU
DESCRIPTION// Share the hardware in groups of 2 people, one group of 3 Create a channel called: KABK_ex1 Read the sensor you used in class with NodeMCU and send those to channel KABK_ex1. Send the data every minute. Keep the sensor running in your house for one week (or few days) Document the process in your blog: —> schematic of the circuit —> code (readable) —> pictures —> screenshots of ThingSpeak platform COMMENT// Alexia and I worked with the dht11 en nodeMCU.  We had some troubles combining the codes because there were some typo’s in the .INO files When we finally managed to work with it, we had troubles connecting it to thingspeak. The problem is likely to be the WiFi or a mistake while combining the code. 
070619 -  The NEW CODE was improved because of a syntax error, dht was not defined and I missed a part about connecting but then when asking Emma we fixed it. It was a good reminder
THINGSPEAK RECENT SCREENSHOT //
Tumblr media Tumblr media
CIRCUIT//
Tumblr media
NEW CODE//
#include <ESP8266WiFi.h> //Including library to use esp8266 #include <DHT.h>  // Including library for dht #include "ThingSpeak.h"   //Including library to send data to thingspeak #define DHTPIN 5          //pin where the dht11 is connected can use int as well define is constant DHT dht(DHTPIN, DHT11);   //create an object dht, define pin and model
//WiFi credentials char ssid[] = "KABK-Students";   // your network SSID (name) char pass[] = "kabk@air";   // your network password
WiFiClient  client;
//ThingSpeak credentials credentials unsigned long myChannelNumber = 778182; //your channel ID char myWriteAPIKey[] = "JGEOO0VKX0OK9OS2"; //"Write API" of your channel
//float data = 345;  //data that I send to thingspeak int wait = 20000; // Time between two uplinks float temp = 0;   //variable where to save temperture float hum = 0;    //variable where to save humidity
int wait2 = 1000;
void setup() {
 Serial.begin(9600);
 WiFi.begin(ssid, pass);
 Serial.print("Connecting");
 while (WiFi.status() != WL_CONNECTED)    {      delay(500);      Serial.print(".");      }
   Serial.println();    Serial.println("\nConnected.");
 dht.begin();          //Initialize DHT
 ThingSpeak.begin(client);  //Initialize ThingSpeak
}
void loop() {
    temp = dht.readTemperature();  //save the temperature in the variable temp     hum = dht.readHumidity();      //save the humidity in the variable hum
    Serial.print("Temperature: "); Serial.print(temp); Serial.println(" °C"); //print on serial temperature     Serial.print("Humidity: "); Serial.print(hum); Serial.println(" %");      //print on serial humidity     Serial.println("");
 // set the ThingSpeak fields with the values  ThingSpeak.setField(2, hum);
 // set the ThingSpeak fields with the values  ThingSpeak.setField(1, temp);
 // send uplink  ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
 // wait before the next measurment  delay(wait);
}
OLD CODE//
#include <ESP8266WiFi.h>
#include "ThingSpeak.h" //include dht library #include <DHT.h> //dht defining #define DHTPIN 1 // DHT dht(DHTPIN, DHT11);
//fluctuates the value of temperature en humidity float temp = dht.readTemperature(); //float hum = 0;
// wait 10 second for new values //int wait = 10000;
//wifi credentials char ssid[] ="newlucht-students"; // this could be YOUR wifi here! char pass[] ="kabk@air"; // password
WiFiClient client; //thingspeak credential unsigned long myChannelNumber = 741403; // define channel nr char myWriteAPIKey[] = "1AHO0V2CFEX804GK"; // define api key of thingspeak // //float temp = 345; // data that I send to thingspeak int wait = 60000; // time between uplinks
void setup(){  Serial.begin(9600);  Serial.println();  dht.begin(); // begin the dht reference
 WiFi.begin(ssid, pass);
 Serial.print("Connecting");
 while (WiFi.status() != WL_CONNECTED)  {    delay(500);    Serial.print(".");  }  Serial.println();  Serial.print("Connected.");
 ThingSpeak.begin(client); // initialize ThingSpeak //  dht.begin(); }
void loop() {
// //set thingspeak fields with given values  ThingSpeak.setField(1, temp);  // send uplink  ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey); //wait for next measurement  delay(wait); //
//  temp = dht.readTemperature(); //variable reading temperature //  hum = dht.readHumidity(); //variable reading humidity
//   Serial.print("Temperature:"); Serial.print(temp); Serial.println("'C"); //Serial.print("Humidity:"); Serial.print(hum); Serial.println(" %"); Serial.println(""); delay(wait);
}
//CODE 
SCREENSHOTS OF THINGSPEAK
Tumblr media Tumblr media
PHOTOS OF NODEMCU + DHT11
Tumblr media
0 notes
lorenzoquintimd · 6 years ago
Text
WEEK 4: MyMath
Write a sketch and call it: “MyMath.ino”.In MyMath create four functions that execute the four calculations :and call the functions: 
MyMultiplication, 
MyAddition, 
MySubtraction,
MyDivision.
CODE
void setup() { // put your setup code here, to run once: Serial.begin(9600); }
void loop() { //: int i = 2; //integer variable i is set to pin 2  int j = 3; //integer variable j is set to pin 3 int k; // integer variable k
k = myMultiply(i,j); //  variable k is set to multiply  variable i by  variable j Serial.println(k); // prints  variable k delay(1000); // delay in 1000ms 
k = myAddition(i, j); // variable k is set to add variable i to  variable j Serial.println(k);  // prints  variable k delay(1000); // delay in 1000ms
k = mySubtraction(i, j);  // variable k is set to substract variable i from variable j Serial.println(k); // prints  variable k delay(1000); // delay in 1000ms
k = myDivision(i, j);  // variable k is set to divice variable i from variable j Serial.println(k); prints  variable k delay(1000); // delay in 1000ms
}
int myMultiply (int x, int y) { int result = x*y; return result; }
int myAddition (int x, int y) { int result = x + y; return result; }
int myDivision(int x, int y){ float result = x/y; return result; }
int mySubtraction(int x, int y){ int result = y - x; return result;
}
0 notes
lorenzoquintimd · 6 years ago
Video
tumblr
WEEK 3 SENSOR AND BUZZER: 
• Input device: select a sensor from the Arduino and Sensor kits. The input device must be used to sense the presence of a person.
• Output device: passive buzzer 
• Functionality: trigger a melody or sound using the input device. 
• Decide the story of your project (where would you use it? What is the circumstance in which you detect the person), make the schematic, make the circuit on breadboard, define the functionality, write the code, document it.
Xiaoyao and I chose the KY013 Analog Temperature Sensor
Tumblr media
This is a Analog Temperature Sensor that measures ambient temperature. It is based on the resistance of the thermistor.
^Thermistor
If the temperature is < 27 °C , the buzzer reacts to the temperature input.
What it read:
Tumblr media
SKETCH MADE IN FRITZING:
Tumblr media
CODE
/* * Lorenzo Quint
* November 14 * Based on example from: https://arduinomodules.info/ky-013-analog-temperature-sensor-module/ */ #include <math.h> int led_pin = 2; // digital pin for the led int sensorPin = A0; // select the input pin for the potentiometer int buzzer = 8; // digital pin for the buzzer
double Thermistor(int RawADC) { double Temp; Temp = log(10000.0*((1024.0/RawADC-1))); Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp ); Temp = Temp - 273.15;            // Convert Kelvin to Celcius //Temp = (Temp * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit return Temp; }
void setup() { pinMode(buzzer, OUTPUT); // Stating that the buzzer is the output Serial.begin(9600); // Serial code to read / test if it’s working.   }
void loop() { int readVal=analogRead(sensorPin); // an integer to read the value of an analog sensor double temp =  Thermistor(readVal); //
// if statement to say if the temperature is under 27 degrees, the buzzer will react, if it’s not, there’s no sound.
if(temp < 27){ tone(buzzer,1000); } else { noTone(buzzer); }
Serial.println(temp);  // display temperature //Serial.println(readVal);  // display temperature
delay(500); // delay of 500 ms }
0 notes
lorenzoquintimd · 6 years ago
Text
Flavour of Choice! Made with Xiaoyao Ma
** We will use a Teabox  ** Multiple Choice  ->  Answer -> Teabox
** Switch = input 
** LCD Screen = output ** Buttons -> Info -> LCD Screen -> teachoice - code (with comments!!)
/* *  Xiaoyao & Lorenzo *  Tea Box Project *  This code is the input part of the project *  the input includes three switches *   */
//delcaring switch pins int sw1_pin = 2; int sw2_pin = 3; int sw3_pin = 4;
//current state of the switches int sw1_state = 0; int sw2_state = 0; int sw3_state = 0;
//previous state of the switches int sw1_preState = 1; int sw2_preState = 1; int sw3_preState = 1;
//counter for the number of presses int sw1_counter = 0; int sw2_counter = 0; int sw3_counter = 0;
boolean OnePressed = false; boolean TwoPressed = false; boolean ThreePressed = false;
#include <Wire.h> #include <LiquidCrystal_I2C.h> // Set the LCD I2C address LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  
void setup() {  lcd.begin(16,2); //initialize lcd  lcd.backlight();
 // initialize the button pins  pinMode(sw1_pin, INPUT_PULLUP);  pinMode(sw2_pin, INPUT_PULLUP);  pinMode(sw3_pin, INPUT_PULLUP);
 Serial.begin(9600);
}
void loop() { //  if(sw1_counter == 0 && sw2_counter == 0 && sw3_counter == 0 ){ //  homeScreen(); //  }
 // read the switch state  sw1_state = digitalRead(sw1_pin);  sw2_state = digitalRead(sw2_pin);  sw3_state = digitalRead(sw3_pin);
// if sw1 is pressed  if(sw1_state != sw1_preState && sw1_state == HIGH) {    OnePressed = true;    sw1_counter += 1;
   delay(200);  }  Serial.print("sw1_presses:");  Serial.print(sw1_counter);  Serial.print(" sw1_state");  Serial.println(sw1_state);
 sw1_preState = sw1_state;
 // if sw2 is pressed  if(sw2_state != sw2_preState && sw2_state == HIGH) {    TwoPressed = true;    sw2_counter += 1;
   delay(200);  }  Serial.print("sw2_presses:");  Serial.println(sw2_counter);
 sw2_preState = sw2_state;
 //if sw3 is pressed  if(sw3_state != sw3_preState && sw3_state == HIGH) {    ThreePressed = true;    sw3_counter += 1;
   delay(200);  }  Serial.print("sw3_presses:");  Serial.println(sw3_counter);  Serial.println(" ");
 sw3_preState = sw3_state;
 switch(sw1_counter){    case 1:    {       switch(sw2_counter){        case 1:        {          optionTwo();        }        break;
       case 2:        {          reset();        }        break;
   }      switch(sw3_counter){        case 1:        {          optionThree();        }        break;
       case 2:        {          reset();        }        break;
       //default:
     }      questionScreen();    }    break;
   case 2:    {      optionOne();    }    break;
   case 3:    {      reset();    }    break;
   default:    switchTwo();
 }
//first press switch 2
//first press sw3
//  if(sw1_counter > 2){ //    sw1_counter = 0; //  } // //    if(sw2_counter > 2){ //    sw2_counter = 0; //  } // //    if(sw3_counter > 2){ //    sw3_counter = 0; //  }
}
void switchTwo() {   switch(sw2_counter){    case 1:    {      switch(sw1_counter){        case 1:        {          optionFour();                }        break;        case 2:        {          reset();        }        break;      }
     switch(sw3_counter){        case 1:        {          optionSix();        }        break;
       case 2:        {          reset();        }        break;
//        default: //        questionScreen(); //        break;      }      questionScreen();    }    break;
   case 2:    {      optionFive();    }    break;
   case 3:    {      reset();    }    break;
   default:  switchThree();  }
}
void switchThree(){    switch(sw3_counter){    case 1:    {      switch(sw1_counter){        case 1:        {          optionSeven();        }        break;
       case 2:        {          reset();            }        break;      }
     switch(sw2_counter){        case 1:        {          optionEight();        }        break;        case 2:        {          reset();        }        break;
//        default: //        questionScreen(); //        break;      }      questionScreen();    }    break;
   case 2:    {      optionNine();    }    break;
   case 3:    {      reset();    }    break;
   default:    homeScreen();  }
}
void homeScreen() {  lcd.clear();  lcd.setCursor(0,0);  lcd.print("how r u feelin'?");  lcd.setCursor(0,1);  lcd.print(":(     :S     :D");
}
void questionScreen() {  lcd.clear();  lcd.setCursor(0,0);  lcd.print("R U worried?");  lcd.setCursor(0,1);  lcd.print("yes  bit   N"); }
void optionOne() {  lcd.clear();  lcd.setCursor(0,0);  lcd.print("100/100");  lcd.setCursor(0,1);  lcd.print("VALERIAN"); }
void optionTwo() {  lcd.clear();  lcd.setCursor(0,0);  lcd.print("100/010");  lcd.setCursor(0,1);  lcd.print("BLACK TEA"); }
void optionThree() {  lcd.clear();  lcd.setCursor(0,0);  lcd.print("100/001");  lcd.setCursor(0,1);  lcd.print("CHAI"); }
void optionFour() {  lcd.clear();  lcd.setCursor(0,0);  lcd.print("010/100");  lcd.setCursor(0,1);  lcd.print("LAVENDER"); }
void optionFive() {  lcd.clear();  lcd.setCursor(0,0);  lcd.print("010/010");  lcd.setCursor(0,1);  lcd.print("MINT"); }
void optionSix() {  lcd.clear();  lcd.setCursor(0,0);  lcd.print("010/001");  lcd.setCursor(0,1);  lcd.print("ROOIBOS"); }
void optionSeven() {  lcd.clear();  lcd.setCursor(0,0);  lcd.print("001/100");  lcd.setCursor(0,1);  lcd.print("CHAMOMILE"); }
void optionEight() {  lcd.clear();  lcd.setCursor(0,0);  lcd.print("001/010");  lcd.setCursor(0,1);  lcd.print("FOREST FRUIT"); }
void optionNine() {  lcd.clear();  lcd.setCursor(0,0);  lcd.print("001/001");  lcd.setCursor(0,1);  lcd.print("DRAGON MIX"); }
void reset() {  sw1_counter = 0;  sw2_counter = 0;  sw3_counter = 0;  OnePressed = false;  TwoPressed = false;  ThreePressed = false;  //homeScreen(); }
- pictures and video of the project.
Tumblr media Tumblr media Tumblr media Tumblr media Tumblr media
0 notes
lorenzoquintimd · 7 years ago
Link
0 notes
lorenzoquintimd · 7 years ago
Link
MyRainbow_LightSensor #include <Adafruit_NeoPixel.h> #ifdef __AVR__  #include <avr/power.h> #endif
#define PIN 6
int ldr_pin = A1;//define the pin of the LDR
int ldr_value = 0;//variable to save the ldr values
// Parameter 1 = number of pixels in strip // Parameter 2 = Arduino pin number (most are valid) // Parameter 3 = pixel type flags, add together as needed: //   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) //   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) //   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products) //   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) //   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products) Adafruit_NeoPixel strip = Adafruit_NeoPixel(12, PIN, NEO_GRB + NEO_KHZ800);
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across // pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input // and minimize distance between Arduino and first pixel.  Avoid connecting // on a live circuit...if you must, connect GND first.
void setup() {
   pinMode(ldr_pin, INPUT);  // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket  #if defined (__AVR_ATtiny85__)    if (F_CPU == 16000000) clock_prescale_set(clock_div_1);  #endif  // End of trinket special code
 strip.begin();  strip.show(); // Initialize all pixels to 'off' }
void loop() {
  ldr_value = analogRead(ldr_pin); // read the ldr
  if(ldr_value < 800) {  // Some example procedures showing how to display to the pixels:      rainbow(50);   } }
void rainbow(uint8_t wait) {  uint16_t i, j;
 for(j=0; j<256; j++) {    for(i=0; i<strip.numPixels(); i++) {      strip.setPixelColor(i, Wheel((i+j) & 255));    }    strip.show();    delay(wait);  } }
// Input a value 0 to 255 to get a color value. // The colours are a transition r - g - b - back to r. uint32_t Wheel(byte WheelPos) {  WheelPos = 255 - WheelPos;  if(WheelPos < 85) {    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);  }  if(WheelPos < 170) {    WheelPos -= 85;    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);  }  WheelPos -= 170;  return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0); }
0 notes
lorenzoquintimd · 7 years ago
Video
tumblr
lesson 3 - Connect Sensor Input to Output 
Tumblr media
#include <OneWire.h> #include <DallasTemperature.h>
// Data wire is plugged into pin 2 on the Arduino #define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire devices // (not just Maxim/Dallas temperature ICs) OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature. DallasTemperature sensors(&oneWire);
int led_pin = 3;//declaring led pin number void setup(void) {  pinMode(led_pin, OUTPUT);
 // start serial port  Serial.begin(9600);  Serial.println("Dallas Temperature IC Control Library Demo");
 // Start up the library  sensors.begin(); }
void loop(void) {  // call sensors.requestTemperatures() to issue a global temperature  // request to all devices on the bus  Serial.print(" Requesting temperatures...");  sensors.requestTemperatures(); // Send the command to get temperatures  Serial.println("DONE");
 Serial.print("Temperature is: ");  Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"?    // You can have more than one IC on the same bus.    // 0 refers to the first IC on the wire    delay(1000);
   if(sensors.getTempCByIndex(0) > 28){      digitalWrite(led_pin,HIGH);    }
}
0 notes
lorenzoquintimd · 7 years ago
Video
tumblr
Tumblr media
Assignment 03 Project 01
Finish the dice. Combine the counter code with the random sequence code to reproduce the behavior of a Dice. The dice will work in three steps:
1- Launch the dice -> press the switch
2- Get the random number
3- Reset the game for the next player -> press the switch again
At first, the LED lights won’t stay on for the right number because the output command is in loop(), which generates a different randomNumber for every loop. Therefore every loop different number of lights turn on. Which means before the buttonState changes, the different number of LED lights will keep turning on.
Code:
/* * Lorenzo - November 2018 * press the switch to launch the dice * the dice gives a random number * game reset - press switch to get the next number */
// this constant won’t change: const int  buttonPin = A0;    // the pin that the pushbutton is attached to int ledPins[] = {2,3,4,5,6,7}; // an array of pin number to which LEDs are attached int pinCount = 6;     //the numebr of pins/length of the array int randomNumber = 0;   //declare a variable for randomNumber
// Variables will change: int buttonPushCounter = 0;   // counter for the number of button presses int buttonState = 0;         // current state of the button_ the value doesn’t matter because it’s immediately resetted int lastButtonState = 1;     // previous state of the button
void setup() { // initialize the button pin as a input: pinMode(buttonPin, INPUT_PULLUP); //use a for loop to initialize led pins as an output for(int thisPin = 0; thisPin < pinCount; thisPin++){   pinMode(ledPins[thisPin] ,OUTPUT); }
// initialize serial communication: Serial.begin(9600); }
void loop() {
// read the pushbutton input pin: buttonState = digitalRead(buttonPin);
// compare the buttonState to its previous state(comparing the voltages) if (buttonState != lastButtonState && buttonState == HIGH) {   //if the current state is high & if the state has changed     buttonPushCounter += 1;  
  // Delay a little bit to avoid bouncing   delay(50); }
// lighting up the LEDs if button pressed    //generate a random number from 1-6 if(buttonPushCounter  == 1){   randomNumber = random(1,7);   for (int thisPin = 0; thisPin < randomNumber; thisPin++){     digitalWrite(ledPins[thisPin],HIGH);     delay(100); //delay time for turning up each led   }
}
if(buttonPushCounter == 2) {    for (int thisPin = pinCount; thisPin >= 0; thisPin–){     digitalWrite(ledPins[thisPin],LOW);   }   buttonPushCounter = 0; }
Serial.print(“Counter: ”); Serial.println(buttonState);
lastButtonState = buttonState;
}
So then we added a delay after all the LEDs are turned on. We also deleted the condition to turn off the LED lights when the button is pressed the second time.
delay(1000);
//if(buttonPushCounter == 2) {   for (int thisPin = pinCount; thisPin >= 0; thisPin–){    digitalWrite(ledPins[thisPin],LOW);  }  buttonPushCounter = 0; //}
So that all the LEDs are shut down after they’re turned on.
0 notes
lorenzoquintimd · 7 years ago
Video
tumblr
/* Arduino Dice :)
This example shows how to simulate throwing a dice with 6 LEDs.
The circuit: * 6 LEDs attached to consecutive digital pins (with 220 Ohm resistors) * Button switch connected to digital pin (see circuit on https://www.arduino.cc/en/Tutorial/Button)
Created 5 Jan 2017 By Esther van der Stappen
This example code is in the public domain.
*/
// set to 1 if we're debugging #define DEBUG 0
// 6 consecutive digital pins for the LEDs int first = 2; int second = 3; int third = 4; int fourth = 5; int fifth = 6; int sixth = 7;
// pin for the button switch int button = 12; // value to check state of button switch int pressed = 0;
void setup() {  // set all LED pins to OUTPUT  for (int i=first; i<=sixth; i++) {    pinMode(i, OUTPUT);  }  // set buttin pin to INPUT  pinMode(button, INPUT);
 // initialize random seed by noise from analog pin 0 (should be unconnected)  randomSeed(analogRead(0));
 // if we're debugging, connect to serial  #ifdef DEBUG    Serial.begin(9600);  #endif
}
void buildUpTension() {  // light LEDs from left to right and back to build up tension  // while waiting for the dice to be thrown  // left to right  for (int i=first; i<=sixth; i++) {    if (i!=first) {      digitalWrite(i-1, LOW);    }    digitalWrite(i, HIGH);    delay(100);  }  // right to left  for (int i=sixth; i>=first; i--) {    if (i!=sixth) {      digitalWrite(i+1, LOW);    }    digitalWrite(i, HIGH);    delay(100);  } }
void showNumber(int number) {  digitalWrite(first, HIGH);  if (number >= 2) {    digitalWrite(second, HIGH);  }  if (number >= 3) {    digitalWrite(third, HIGH);      }  if (number >= 4) {    digitalWrite(fourth, HIGH);      }  if (number >= 5) {    digitalWrite(fifth, HIGH);      }  if (number == 6) {    digitalWrite(sixth, HIGH);      } }
int throwDice() {  // get a random number in the range [1,6]  int randNumber = random(1,7);
 #ifdef DEBUG    Serial.println(randNumber);  #endif
 return randNumber; }
void setAllLEDs(int value) {  for (int i=first; i<=sixth; i++) {    digitalWrite(i, value);  } }
void loop() {  // if button is pressed - throw the dice  pressed = digitalRead(button);
 if (pressed == HIGH) {    // remove previous number    setAllLEDs(LOW);
   buildUpTension();    int thrownNumber = throwDice();    showNumber(thrownNumber);  }
} src: https://create.arduino.cc/projecthub/EvdS/led-dice-885cf1?ref=search&ref_id=led%20&offset=2
Tumblr media
0 notes