Dodajem treće i četvrto predavanje.

This commit is contained in:
2024-04-10 09:13:23 +02:00
parent 2e95796816
commit 44c02255b4
14 changed files with 209 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
const int fotootpornik = A0; // Fotootpornik povezan na analogni pin A0
int value; // Prati vrednost napona na otporniku
void setup()
{
Serial.begin(9600); // Inicijalizuje komunikaciju sa računarom pri brzini od 9600 bit/s
}
void loop()
{
value = analogRead(fotootpornik); // Čita vrednost na otporniku
Serial.println(value); // Štampa tu vrednost na serijski monitor
delay(50); // Pauza
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

View File

@@ -0,0 +1,2 @@
default_port: /dev/ttyUSB0
default_fqbn: arduino:avr:uno

View File

@@ -0,0 +1,22 @@
const int fotootpornik = A0; // Fotootpornik je povezan na analogni pin A0
const int led = 13; // Dioda povezana na pin 13
int value; // Prati napon na fotootporniku
void setup()
{
pinMode(led, OUTPUT); // Inicijalizuje pin 13 kao izlaz
digitalWrite(led, LOW); // Postavlja diodu kao isključenu (za svaki slučaj)
Serial.begin(9600); // Inicijalizuje komunikaciju sa računarom pri brzini od 9600 bit/s
}
void loop()
{
value = analogRead(fotootpornik); // Čita napon na otporniku
Serial.println(value); // Štampa vrednost na serijski monitor
if (value < 200) // Ako je vrednost manja od 200 uključi led
digitalWrite(led, HIGH);
else // Ako nije, isključi led
digitalWrite(led, LOW);
delay(50); // Pauza između očitavanja
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

View File

@@ -0,0 +1,2 @@
default_port: /dev/ttyUSB0
default_fqbn: arduino:avr:uno

View File

@@ -0,0 +1,2 @@
default_port: /dev/ttyUSB0
default_fqbn: arduino:avr:uno

View File

@@ -0,0 +1,31 @@
//https://randomnerdtutorials.com/guide-for-ds18b20-temperature-sensor-with-arduino/
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is conntec to the Arduino digital pin 4
#define ONE_WIRE_BUS 4
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
void setup(void)
{
// Start serial communication for debugging purposes
Serial.begin(9600);
// Start up the library
sensors.begin();
}
void loop(void){
// Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
sensors.requestTemperatures();
Serial.print("Celsius temperature: ");
// Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
Serial.println(sensors.getTempCByIndex(0));
delay(1000);
}

Binary file not shown.

View File

@@ -0,0 +1,2 @@
default_port: /dev/ttyUSB0
default_fqbn: arduino:avr:uno

View File

@@ -0,0 +1,21 @@
const int temp_sensor = A0; // Senzor je povezan na A0
float sensor_value;
float voltage;
float temperaturaK = 0;
float temperatura = 0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
sensor_value = analogRead(temp_sensor); // Očitana vrednost sa ADC-a
voltage = sensor_value * 5000 / 1024; // Napon u milivoltima
temperaturaK = voltage / 10; // Temperatura u kelvinima
temperatura = temperaturaK - 273.16; // Temperatura u celzijusima
Serial.println(temperatura);
delay(100);
}