Week5 — Arduino 1: The Basics

Yufei Zhang
Computational Craft
1 min readDec 15, 2019

I designed a circuit consisting of a sensor and three LED lights. Different body parts are connected to the circuit. Depending on the resistance of the connected circuit, different LEDs will be lit. The more LEDs that are lit, the larger the current in the circuit.

Arduino Code:

int led1 = 9;
int led2 = 10;
int led3 = 11;
int sensorRead = A0;

int hold01 = 200;
int hold02 = 300;
int hold03 = 400 ;

void setup() {
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);
Serial.begin(9600);
}

void loop() {
int sensor = analogRead(sensorRead);
Serial.println(sensor);
if((sensor >= hold01)&&(sensor < hold02)){
analogWrite(led1,180);
//Serial.println(“1!!!”);
}else if((sensor >= hold02)&&(sensor < hold03)){
analogWrite(led2,180);
analogWrite(led1,180);
//Serial.println(“2!!!”);
}else if(sensor >= hold03){
analogWrite(led3,180);
analogWrite(led2,180);
analogWrite(led1,180);
//Serial.println(“3!!!”);
}else{
digitalWrite(led1,LOW);
digitalWrite(led2,LOW);
digitalWrite(led3,LOW);
}

}

--

--