//Program by Jeremy Blum //www.jeremyblum.com //This will turn on an LED after a threshold int sensePin = 0; int ledPin = 9; void setup() { //Note: We don't need to specifiy sensePin as an //input, since it defaults to that when we read it
//The LED pin needs to be set as an output pinMode(ledPin, OUTPUT); //This is the default value, but we can set it anyways analogReference(DEFAULT); //5V Reference on UNO } void loop() { // read the sensor int val = analogRead(sensePin); if(val < 800) { digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); } }
---------------------------------------------
//Program by Jeremy Blum //www.jeremyblum.com //This will turn on an LED after a threshold int sensePin = 0; int ledPin = 9; void setup() { //Note: We don't need to specifiy sensePin as an //input, since it defaults to that when we read it //The LED pin needs to be set as an output pinMode(ledPin, OUTPUT); //This is the default value, but we can set it anyways analogReference(DEFAULT); //5V Reference on UNO } void loop() { // read the sensor int val = analogRead(sensePin); if(val < 800) { digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); } }
------------------------------------
//Program by Jeremy Blum //www.jeremyblum.com //Turn on an LED if a room is dim, and motion is detected //Define Pins int motionPin = 0; int lightPin = 1; int ledPin = 9; //Distance Variables int lastDist = 0; int currentDist = 0; //Threshold for Movement int thresh = 200; void setup() { //The LED pin needs to be set as an output pinMode(ledPin, OUTPUT); } void loop() { // read the sensor int lightVal = analogRead(lightPin); currentDist = analogRead(motionPin); //Does the current distance deviate from the last distance by more than the threshold? if ((currentDist > lastDist + thresh || currentDist < lastDist - thresh) && lightVal < 800) { digitalWrite(ledPin, HIGH); delay(1000); } else { digitalWrite(ledPin, LOW); } lastDist = currentDist; }
---------------------------------------------
//Program by Jeremy Blum //www.jeremyblum.com //Reads and analog sensor and displays the value int sensePin = 0; void setup() { //Note: We don't need to specifiy sensePin as an //input, since it defaults to that when we read it //This is the default value, but we can set it anyways analogReference(DEFAULT); //5V Reference on UNO //Allows us to listen to serial communications from the arduino Serial.begin(9600); } void loop() { // print the button state to a serial terminal Serial.println(analogRead(sensePin)); delay(500); //wait half a second, then print again. }
Achei esse cara pesquisando por ai ele cria VideoAulas toda semana sobre arduino e como criar coisas passo a passo muito simples e fácil.
Já esta na semana 11 mas eu colocarei aqui pouco à pouco por falta de tempo.
Para quem não entende inglês estarei explicando abaixo basicamente o que ele fez, mesmo sendo extremamente intuitivo o video não precisando necessariamente de tradução mas...
Episódio 1
Esse Episódio em específico trata sobre:
--> Arduino
--> LED
--> C/C++
--> Efeitos Pisca-Pisca (Blink no arduino.cc)
Após o video todos os código que precisara e circuitos:
/* Jeremy's First Program It's awesome! */
int ledPin = 13;
void setup() { //initialize pins as outputs pinMode(ledPin, OUTPUT); }