pages
home
compiler
code compiler
electronics
notes about electronics
laboratory
laboratory
Processing
Processing code compiler
Theremino
Theremino code compiler
logggin
accedi o esci
tutorials Arduino
lights
my first led turns on
led's games
an electronic dice
traffic lights
candle effect
fading effect
red-green-blue 1
red-green-blue 2
7-segment display - Countdown
7-segment display bis
sensors
sensors
Sensor and serial port
sensor PIR
ultrasonic sensor
sound
Theremin
a melody
build a note
switches
buttons
keypad
input via serial port
input via serial port 2
input remote control
input remote control 2
use of variables
custom functions
servos
a robot
a remote-controlled robot
elettronica
mechanics
Italian
handbook
pins
connections
resistors
remarkable sketches
remarkable circuits
Arduino pins
error messages
tables
colour's tables
electrical simbols
referenze on-line
reference Arduino
reference Processing
link
www.arduino.cc
fritzing.org/projects
processing.org
links
hardware
base kit
facilitated kits
advanced kits
Theremino
begins the workshop
review a workshop carried out
my account
info
link
contacts
sensori
introduction
If the ambient light is low turn on one red light ... if it is higher two leds... if it's strong three leds. Let's try this:
from 0 to 80 -> 1 led
from 80 to 160 -> 2 leds
from 160 to 250 -> 3 leds
program
apri il programma
inizia il laboratorio
algorithm
attrezzaggio
pin1
_led1
pin2
_led2
pin3˜
_led3
pinA0
_sensorlight
variabili
A
=
0
ciclo
the variable
A
is equal to... read the sensor:
_sensorlight
IF HAPPENS THAT
A
is less than
80
SWITCH ON (5 Volt)
_led1
SWITCH OFF (0 Volt)
_led2
SWITCH OFF (0 Volt)
_led3
IF HAPPENS THAT
A
is greater than
80
and even IF
A
is less than
0
SWITCH ON (5 Volt)
_led1
SWITCH ON (5 Volt)
_led2
SWITCH OFF (0 Volt)
_led3
IF HAPPENS THAT
A
is greater than
160
SWITCH ON (5 Volt)
_led1
SWITCH ON (5 Volt)
_led2
SWITCH ON (5 Volt)
_led3
wait
500
milliseconds
Arduino code
//programma: sensori //******* pin ******** //******* declare ******** const int pin_led1=1;//pin of _led1 const int pin_led2=2;//pin of _led2 const int pin_led3=3;//pin of _led3 const int pin_sensorlight=A0;//pin sensorluce int A=0;//declares the variable //********** setup ********** void setup(){ pinMode(pin_led1,OUTPUT); pinMode(pin_led2,OUTPUT); pinMode(pin_led3,OUTPUT); pinMode(pin_sensorlight,INPUT); } //********** loop ********** void loop() { A=analogRead(pin_sensorlight); // reads the sensor _sensorlight if(A<80){ digitalWrite(pin_led1,HIGH); // HIGH/LOW is the voltage 5V/0V) digitalWrite(pin_led2,LOW); // HIGH/LOW is the voltage 5V/0V) digitalWrite(pin_led3,LOW); // HIGH/LOW is the voltage 5V/0V) } if(A>80 && A<0){ digitalWrite(pin_led1,HIGH); // HIGH/LOW is the voltage 5V/0V) digitalWrite(pin_led2,HIGH); // HIGH/LOW is the voltage 5V/0V) digitalWrite(pin_led3,LOW); // HIGH/LOW is the voltage 5V/0V) } if(A>160){ digitalWrite(pin_led1,HIGH); // HIGH/LOW is the voltage 5V/0V) digitalWrite(pin_led2,HIGH); // HIGH/LOW is the voltage 5V/0V) digitalWrite(pin_led3,HIGH); // HIGH/LOW is the voltage 5V/0V) } delay(500);//attendi };//end loop //powered by "Arduinomio" (C) //www.mastrohora.it
copy/past in Arduino
electrical connections
here Fritzing's file
logout
Ultima modifica: Agosto 2016