Microcontroller 101: Difference between revisions
Line 100: | Line 100: | ||
==== LDR example ==== | ==== LDR example ==== | ||
example with a light resistor. | |||
keep in mind the LDR pin needs to be a pin with a ADC(analog to digital converter), because you check the analog voltage. on the arduino these are the ANALOG IN pins. on the ESP32 the pins with the ADC(check the pinout graphic) | |||
<pre> | |||
int LDR = 34; //the LDR pin | |||
void setup() { | |||
pinMode(LDR,INPUT); //LDR is an INPUT | |||
} | |||
void loop() { | |||
int value = analogRead(LDR); // read the analog value of the LDR | |||
Serial.println(value); // print the value of the LDR, open serial monitor | |||
delay(10); | |||
} | |||
</pre> | |||
==== LDR & speaker example ==== | ==== LDR & speaker example ==== |
Revision as of 12:23, 11 April 2024
ḿ̬̏ͤͅỉ͔͖̜͌c͕͗ͤ̕̕r̴̨̦͕̝o̯̱̊͊͢c͕͗ͤ̕̕o̯̱̊͊͢ṇ̤͛̒̍t̲̂̓ͩ̑r̴̨̦͕̝o̯̱̊͊͢l̙͖̑̾ͣl̙͖̑̾ͣẹ̿͋̒̕r̴̨̦͕̝ 1̨̹̦͍̀0̗̜͕̅̃1̨̹̦͍̀
09-04-2024 e͎l͎e͎c͎t͎r͎i͎c͎
https://pzwiki.wdka.nl/mw-mediadesign/images/7/7e/Cricket.mp4
sensors and actuators
introduction to Arduino
LOLIN 32 Installation party :~)
more info about the lolin32 is here: https://www.wemos.cc/en/latest/d32/d32_pro.html
step 1: download Arduino software
step 2: download driver for microcontroller
step 3: install driver
_windows: open Device Manager >> find UART device >> right click and update driver >> select driver
Hello World!
in the Arduino program, select the correct board (WEMOS LOLIN32) and select the USB port you are using (if you are unsure, check the listed ports, unplug and see what changed)
void setup() { Serial.begin(115200); } void loop() { Serial.println("Hello World!"); //sends a message to the computer }
Simple Led blink example
// always use a "preresistor" with the LED, because the 5v coming from the microcontroller is too much // a LED only consumes ~2.5 volt, the resistor the other volt // int ledPin = 23; //the int ledPin is 13 void setup() { pinMode(ledPin,OUTPUT); //ledPin is a OUTPUT } void loop() { digitalWrite(ledPin,HIGH); //turns pin 13 on delay(500); //stops the loop for 500 milliseconds digitalWrite(ledPin,LOW); //turns pin 13 off delay(500); //stops the loop for 500 milliseconds }
Traffic light example
int RedLedPin = 23; //the int RedLedPin is 13 int GreenLedPin = 22; //the int GreenLedPin is 12 void setup() { pinMode(RedLedPin,OUTPUT); //ledPin is a OUTPUT pinMode(GreenLedPin,OUTPUT); //ledPin is a OUTPUT } void loop() { digitalWrite(GreenLedPin,HIGH); //turns green led on delay(5000); //stops the loop for 5000 milliseconds for(int i = 0; i < 5; i++){ //this for loop gets 5 times repeated digitalWrite(GreenLedPin,LOW); //turns green led off delay(500); //stops the loop for 500 milliseconds digitalWrite(GreenLedPin,HIGH); //turns green led off delay(500); //stops the loop for 500 milliseconds } digitalWrite(GreenLedPin,LOW); //turns green led off digitalWrite(RedLedPin,HIGH); //turns red led on delay(5000); //stops the loop for 5000 milliseconds digitalWrite(RedLedPin,LOW); //turns red led on }
LDR example
example with a light resistor. keep in mind the LDR pin needs to be a pin with a ADC(analog to digital converter), because you check the analog voltage. on the arduino these are the ANALOG IN pins. on the ESP32 the pins with the ADC(check the pinout graphic)
int LDR = 34; //the LDR pin void setup() { pinMode(LDR,INPUT); //LDR is an INPUT } void loop() { int value = analogRead(LDR); // read the analog value of the LDR Serial.println(value); // print the value of the LDR, open serial monitor delay(10); }
LDR & speaker example
Poti example
Poti & speaker example
Button & alarm example
16-04-24
how to document
>> template:
title
This sketch does this
components list
>>for example:
Wemos Lolin32
Led
220ohm resistor
type of sensor