ingewikkelde codes

Hier vind je de codes voor de projecten op de pagina BOUWEN.

Voor een meer gedetailleerde uitleg: bezoek de links die te vinden zijn bij elk project.

1. DEURSLOTSYSTEEM MET ARDUINO

#include<Keypad.h> // KEYPAD LIBRARY FOR KEYPAD INTERFACING
#include<LiquidCrystal.h>
// LIBRARY FOR LCD INTERFACING
#include<Servo.h>// LIBRARY FOR SERVO MOTOR
//#include<String.h>
#define
buzzer 20 // DEFINING PIN FOR BUZZER.

LiquidCrystal lcd(14,15,16,17,18,19);
// PINS FOR LCD

char keys[4][4]={ // LAYOUT OF KEYPAD
{'1','2','3','A'},

{'4','5','6', 'B'},
{'7','8','9', 'C'},
{'*','0','#', 'D'}};

byte
rowPin[4]={4,5,6,7}; // ROW PINS OF KEYPAD
byte colPin[4]={8,9,10,11}; // COLUMN
PINS OF KEYPAD

Servo servo_Motor;
String password = "159"; // SETTING
DEFAULT PASSWORD.
int position = 0; // VARIABLE FOR DETERMINING THE POSITION.

int
wrong = 0; // VARIABLE FOR CALCULATING THE WRONG INPUT.

int redPin = 9; //
DEFINING PIN FOR RED LED
int greenPin = 8; // DEFINING PIN FOR GREEN LED


Keypad keypad=Keypad(makeKeymap(keys),rowPin,colPin,4,4);
// MAPPING THE
KEYPAD.


int total = 0; // VARIABLE TO DETERMINE THE NUMBER OF WRONG ATTEMPTS.

void
setup()
{
pinMode(redPin,OUTPUT);
pinMode(greenPin,OUTPUT);

lcd.begin(16,2);
lcd.print("DOOR
LOCK SYSTEM");
lcd.setCursor(0,2);
lcd.print(" BY:");
delay(2000);
lcd.clear();
lcd.print("Creative");
lcd.setCursor(0,2);
lcd.print("
Engineer");
delay(2000);
lcd.clear();
servo_Motor.attach(3);
setLocked(true);
delay(1000);

pinMode(buzzer,
OUTPUT);
}

void loop()
{

lcd.clear();
lcd.print("Enter
Password:");
delay(100);

char pressed=keypad.getKey();// TAKING
THE INPUT FROM KEYPAD
String key[3];

if(pressed) // IF THE KEY IS
PRESSED
{
lcd.clear();
lcd.print("Enter Password:");
lcd.setCursor(position,2);

lcd.print(pressed);
delay(500);
if(pressed == '*' || pressed == '#')

{
position = 0;
setLocked(true);
lcd.clear();

}

else if(pressed == password[position])
{
key[position]=pressed;

position++;
}

else if (pressed != password[position]
)
{// IN CASE OF WRONG INPUT INCREMENT BOTH WRONG AND POSITION.
wrong++;

position ++;
}

if(position == 3)
{// WHEN
POSITION == 3 THEN CHECK THE FOLLOWING
if( wrong >0) // IF ANY WRONG
INPUT IF GIVEN THEN INCREMENT TOTAL AND
// SET WRONG AND POSITION TO
ZERO.
{
total++;
wrong = 0;

position = 0;
lcd.clear();
lcd.print("WRONG");

lcd.setCursor(5,2);
lcd.print("PASSWORD");

delay(1000);
setLocked(true);
}


else if(position == 3 && wrong == 0)
{// IF NO WRONG VALUE
IS GIVEN THEN DISPLAY THE ACCEPTED PASSWORD AND
// MOVE THE SERVO
MOTOR.
position = 0;
wrong = 0;
lcd.clear();

lcd.print("PASSWORD");
lcd.setCursor(6,2);

lcd.print("ACCEPTED");
delay(2000);
lcd.clear();

lcd.print("Door Open");
delay(2000);
setLocked(false);

}

if(total ==3)// IF TOTAL OF 3 ATTEMPTS ARE DONE BY
ENTERING WRONG PASS
//WORD THEN SOUND A BUZZER AND SET TOTAL TO 0.

{
total=0;
buzzer_beep();

delay(500);
}

}

}



}

void setLocked(int locked)// FUNCTION TO CHANGE STATUS OF SERVO
MOTOR.
{
if (locked)
{
digitalWrite(redPin, HIGH);

digitalWrite(greenPin, LOW);
delay(1000);
servo_Motor.attach(3);

servo_Motor.write(10);
delay(1000);
servo_Motor.detach();

}
else
{
digitalWrite(redPin, LOW);
digitalWrite(greenPin,
HIGH);
delay(1000);
servo_Motor.attach(3);
servo_Motor.write(90);

delay(1000);
servo_Motor.detach();
}
}
void
buzzer_beep()// FUNCTION TO BEEP THE BUZZER.
{
digitalWrite(buzzer,HIGH);

delay(1000);
digitalWrite(buzzer,LOW);
delay(1000);
lcd.clear();

lcd.setCursor(16,0);
lcd.print("Subscribe Channel");
lcd.setCursor(16,1);

lcd.print("For More Videos");
delay(2000);
while(1)
{

lcd.scrollDisplayLeft();
delay(200);
}
}

 

Voor een meer gedetailleerde uitleg raden we u aan om de link te bezoeken, die op de pagina "BOUWEN" staat.

2. ARDUINO WEERSTATION EEN KRACHTIG ARDUINO WEERSTATION KAN JE HELPEN OM PLANTEN EN GAZONS EFFICIËNTER WATER TE GEVEN.

/*

k-NN color classification
-------------------------

This sketch classifies objects using a color sensor.

First you 'teach' the Arduino by putting an example of each object close to the color sensor.
After this the Arduino will guess the name of objects it is shown based on how similar
the color is to the examples it has seen.

This example uses a simple case of k-Nearest Neighbour (k-NN) algorithm where k=1.

HARDWARE: Arduino Nano BLE Sense

USAGE: Follow prompts in serial console. Move object close to the board to sample its color, then move it away.

Works best in a well lit area with objects of different colors.

NOTE: Make sure Serial Monitor's line ending setting is configured for "Newline" or "Both NL & CR".


This example code is in the public domain.

*/

#include <Arduino_KNN.h>
#include <Arduino_APDS9960.h>

const int INPUTS = 3; // Classifier input is color sensor data; red, green and blue levels
const int CLASSES = 3; // Number of objects we will classify (e.g. Apple, Banana, Orange)
const int EXAMPLES_PER_CLASS = 1; // Number of times user needs to show examples for each object

// K=1 means the classifier looks for the single closest color example it's seen previously
const int K = 1;

// Create a new KNNClassifier
KNNClassifier myKNN(INPUTS);

// Names for each class (object type)
String label[CLASSES];

// Array to store data to pass to the KNN library
float color[INPUTS];

// Threshold for color brightness
const float THRESHOLD = 0.98;
int initialAmbient = 0;

void setup() {

Serial.begin(9600);
while (!Serial);

// Pins for the built-in RGB LEDs on the Arduino Nano 33 BLE Sense
pinMode(LEDR, OUTPUT);
pinMode(LEDG, OUTPUT);
pinMode(LEDB, OUTPUT);

if (!APDS.begin()) {
Serial.println("Failled to initialized APDS!");
while (1);
}

initialAmbient = readAmbient();

Serial.println("Arduino k-NN color classifier");

// Ask user for the name of each object
for (int currentClass = 0; currentClass < CLASSES; currentClass++) {

Serial.println("Enter an object name:");
label[currentClass] = readName();

// Ask user to show examples of each object
for (int currentExample = 0; currentExample < EXAMPLES_PER_CLASS; currentExample++) {

Serial.print("Show me an example ");
Serial.println(label[currentClass]);

// Wait for an object then read its color
readColor(color);

// Add example color to the k-NN model
myKNN.addExample(color, currentClass);

}
}
}


void loop() {

int classification;

// Wait for the object to move away again
while (!APDS.proximityAvailable() || APDS.readProximity() == 0) {}

Serial.println("Let me guess your object");

// Wait for an object then read its color
readColor(color);

// Classify the object
classification = myKNN.classify(color, K);

// Print the classification
Serial.println(label[classification]);
Serial.println();

}

int readAmbient() {
int red, green, blue, ambient;
while (!APDS.colorAvailable()) {};
APDS.readColor(red, green, blue, ambient);
return ambient;
}

void readColor(float color[]) {
int red, green, blue, ambient = 0, colorTotal = 0;

// Wait until shadow of object passing
while (readAmbient() > initialAmbient * THRESHOLD) {}

// Wait until we have a color bright enough
while (ambient < initialAmbient * THRESHOLD) {

// Sample if color is available and object is close
if (APDS.colorAvailable()) {

// Read color and proximity
APDS.readColor(red, green, blue, ambient);
colorTotal = (red + green + blue);
}
}

// Normalise the color sample data and put it in the classifier input array
color[0] = (float)red / colorTotal;
color[1] = (float)green / colorTotal;
color[2] = (float)blue / colorTotal;

// Print the red, green and blue percentage values
Serial.print(color[0]);
Serial.print(",");
Serial.print(color[1]);
Serial.print(",");
Serial.println(color[2]);
}


// reads a name from the Serial Monitor
String readName() {
String line;

while (1) {
if (Serial.available()) {
char c = Serial.read();

if (c == '\r') {
// ignore
continue;
} else if (c == '\n') {
break;
}

line += c;
}
}

return line;
}

 

Voor een meer gedetailleerde uitleg raden we u aan om de link te bezoeken, die op de pagina "BOUWEN" staat.

3. ARDUINO-AFSTANDSSENSOR EN OLED.

//rayan kiwan #include <SPI.h> #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1306.h> #define CommonSenseMetricSystem //#define ImperialNonsenseSystem #define trigPin 13 #define echoPin 12 #define OLED_RESET 4 Adafruit_SSD1306 display(OLED_RESET); void setup() { Serial.begin (9600); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); display.begin(SSD1306_SWITCHCAPVCC, 0x3C); //initialize with the I2C addr 0x3C (128x64) display.clearDisplay(); } void loop() { long duration, distance; digitalWrite(trigPin, LOW); //PULSE ___|---|___ delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); #ifdef CommonSenseMetricSystem distance = (duration/2) / 29.1; #endif #ifdef ImperialNonsenseSystem distance = (duration/2) / 73.914; #endif display.setCursor(22,20); //oled display display.setTextSize(3); display.setTextColor(WHITE); display.println(distance); display.setCursor(85,20); display.setTextSize(3); #ifdef CommonSenseMetricSystem display.println("cm"); #endif #ifdef ImperialNonsenseSystem display.println("in"); #endif display.display(); delay(500); display.clearDisplay(); Serial.println(distance);//debug }

Voor een meer gedetailleerde uitleg raden we u aan om de link te bezoeken, die op de pagina "BOUWEN" staat.

4. IOT-WEERDATALOGGER MET BLUES WIRELESS & QUBITRO

Dit is een erg ingewikkeld project, waarbij een simpele code niet genoeg is, we raden u dus aan om de volgende site te bezoeken:

https://www.hackster.io/pradeeplogu0/iot-weather-data-logger-using-blues-wireless-qubitro-215648

5. GEMOTORISEERDE CAMERABASIS MET BEWEGINGSDETECTIE.

/************************************************* *** The Motion Following Motorized Camera Base *** *** by Lindsay Fox *** *************************************************/ // Servor motor #include <Servo.h> Servo camServo; // name the servo motor controlling the camera base int currentPIRposition = 0; // set current angle of servo // LED status lights int LEDpin[] = {9,10,11,12,13}; // LED pin numbers int currentLEDpin = 9; // the current LED pin; begin with the first in the sequence above // PIR sensors int PIRpin[] = {2,3,4,5,6}; // PIR pin numbers int currentPIRpin = 2; // the current PIR pin; begin with the first in the sequence above int PIRprevState[] = {1,1,1,1,1}; // the previous state of the PIR (0 = LOW, 1 = HIGH) int PIRposition[] = {157,117.75,78.5,39.25,0}; // assign angles for servo motor (0-157 distributed equally between 5 PIR sensors) boolean PIRstatus; // Set status of PIR sensor as either true or false ///// SETUP ////////////////////////////////////// void setup() { Serial.begin(9600); camServo.attach(7); // assign servo pin for (int p = 0; p < 5; p++) { // set all PIR sensors as INPUTS pinMode(PIRpin[p], INPUT); } // end 'p' for for (int l = 0; l < 5; l++) { // set all LEDs as OUTPUTS pinMode(LEDpin[l], OUTPUT); } // end 'l' for /////// CALIBRATE PIR SENSORS /////// Serial.print("Calibrating PIR Sensors "); for(int c = 0; c < 15; c++){ // calibrate PIR sensors for 15 seconds (change from 10-60 sec depending on your sensors) Serial.print("."); delay(1000); // wait 1 second } // end calibration for Serial.println("PIR Sensors Ready"); camServo.write(78.5); // move the servo to the center position to begin } // end setup ///// MAIN LOOP ////////////////////////////////// void loop() { for (int PIR = 0; PIR < 5; PIR++) { // start this loop for each PIR sensor currentPIRpin = PIRpin[PIR]; // set current PIR pin to current number in 'for' loop currentLEDpin=LEDpin[PIR]; // set current LED pin to current number in 'for' loop PIRstatus = digitalRead(currentPIRpin); if (PIRstatus == HIGH) { // if motion is detected on current PIR sensor digitalWrite(currentLEDpin, HIGH); // turn corresponding LED on if(PIRprevState[PIR] == 0) { // if PIR sensor's previous state is LOW if (currentPIRposition != currentPIRpin && PIRprevState[PIR] == 0) { // if high PIR is different than current position PIR then move to new position camServo.write(PIRposition[PIR]); Serial.print("Current angle : "); Serial.println(PIRposition[PIR]); delay(50); currentPIRposition = currentPIRpin; // reset current PIR position to active [PIR] pin PIRprevState[PIR] = 1; // set previous PIR state to HIGH } PIRprevState[PIR] = 1; // set previous PIR state to HIGH if the current position is the same as the current PIR pin } // end PIRprevState if } // end PIRstatus if else { // digitalWrite(currentLEDpin, LOW); //the led visualizes the sensors output pin state PIRprevState[PIR] = 0; // set previous PIR state to LOW } // end else } // end [PIR] for loop } // end main loop

Voor een meer gedetailleerde uitleg raden we u aan om de link te bezoeken, die op de pagina "BOUWEN" staat.

6. ARDUINO ROBOTBARTENDER – 3D-PRINTBAAR & BLUETOOTH.

Dit is een erg ingewikkeld project, waarbij een simpele code niet genoeg is, we raden u dus aan om de volgende site te bezoeken:

https://www.instructables.com/Arduino-Robotic-Bartender-3D-Printable-Bluetooth/