Меню сайта

06.04.2020

Разбираем состав набора ардуино,  устанавливаем и настраиваем  программу.

Состав стартового набора ардуино

 

Скачать среду разработки можно с официального сайта ардуино
Инструкция по установке драйвера для китайской ардуино тут


13.04.2020

Датчик освещенности

Схема подключения:

Скетч:

int sensePin =0;
int ledPin =3;

void setup()
{
pinMode(ledPin, OUTPUT);
}

void loop() {
int val = analogRead(sensePin);

val = constrain(val, 750, 900);
int ledLevel = map(val, 750, 900, 255, 0);

analogWrite(ledPin, ledLevel);
}


20.04.2020

RGB светодиод

Схема подключения:

Скетч:

const int RED_PIN = 9;
const int GREEN_PIN = 10;
const int BLUE_PIN = 11;

void setup()
{
pinMode(RED_PIN, OUTPUT);
pinMode(GREEN_PIN, OUTPUT);
pinMode(BLUE_PIN, OUTPUT);
}

void loop()
{
mainColors();
showSpectrum();
}

void mainColors()
{
digitalWrite(RED_PIN, LOW);
digitalWrite(GREEN_PIN, LOW);
digitalWrite(BLUE_PIN, LOW);

delay(1000);

digitalWrite(RED_PIN, HIGH);
digitalWrite(GREEN_PIN, LOW);
digitalWrite(BLUE_PIN, LOW);

delay(1000);

digitalWrite(RED_PIN, LOW);
digitalWrite(GREEN_PIN, HIGH);
digitalWrite(BLUE_PIN, LOW);

delay(1000);

digitalWrite(RED_PIN, LOW);
digitalWrite(GREEN_PIN, LOW);
digitalWrite(BLUE_PIN, HIGH);

delay(1000);

digitalWrite(RED_PIN, HIGH);
digitalWrite(GREEN_PIN, HIGH);
digitalWrite(BLUE_PIN, LOW);

delay(1000);

digitalWrite(RED_PIN, LOW);
digitalWrite(GREEN_PIN, HIGH);
digitalWrite(BLUE_PIN, HIGH);

delay(1000);

digitalWrite(RED_PIN, HIGH);
digitalWrite(GREEN_PIN, LOW);
digitalWrite(BLUE_PIN, HIGH);

delay(1000);

digitalWrite(RED_PIN, HIGH);
digitalWrite(GREEN_PIN, HIGH);
digitalWrite(BLUE_PIN, HIGH);

delay(1000);
}

void showSpectrum()
{
int x;
for (x = 0; x < 768; x++)
{
showRGB(x);
delay(10);
}
}

void showRGB(int color)
{
int redIntensity;
int greenIntensity;
int blueIntensity;

if (color <= 255)
{
redIntensity = 255 — color;
greenIntensity = color;
blueIntensity = 0;
}
else if (color <= 511)
{
redIntensity = 0;
greenIntensity = 255 — (color — 256);
blueIntensity = (color — 256);
}
else // color >= 512
{
redIntensity = (color — 512);
greenIntensity = 0;
blueIntensity = 255 — (color — 512);
}
analogWrite(RED_PIN, redIntensity);
analogWrite(BLUE_PIN, blueIntensity);
analogWrite(GREEN_PIN, greenIntensity);
}


27.04.2020

Сервопривод, библиотеки

Схема подключения:

Скетч:

// библиотека с коммандами для сервоприводов
#include <Servo.h>
//описание библиотеки по ссылке — arduino.cc/en/Reference/Servo

Servo servo1; // объект сервопривод №1

void setup()
{
servo1.attach(9); // Сервопривод подключен к цифровому выходу 9
//servo1.detach() для расслабления мотора сервопривода
}

void loop()
{
int position; //зададим переменную позиция, понадобится потом

// Крутилка на полной скорости:

servo1.write(90); // повернись на 90 град.
delay(1000); // пауза чтобы он успел повернуться
servo1.write(180); // повернись на 180 град.
delay(1000); // пауза
servo1.write(0); // повернись до уровня 0 град.
delay(1000); // пауза

// Крутилки на более низкой скорости:
//от 0 до 180 с гагом в 2 градуса

for(position = 0; position < 180; position += 2)
{
servo1.write(position); // передвинься на следующую позицию
delay(20); // небольшой перерыв чтобы он успел передвинуться
}

// от 180 до 0 с шагом 1 градус

for(position = 180; position >= 0; position -= 1)
{
servo1.write(position); // передвинься на следующую позицию
delay(20); // небольшой перерыв чтобы он успел передвинуться
}
}

12.05.2020

Датчик температуры DHT11

Схема подключения:

Скетч:

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <DHT.h>
#define dht_apin A0 // Analog Pin sensor is connected to

dht DHT;

void setup(){

Serial.begin(9600);
delay(500);//Delay to let system boot
Serial.println(«DHT11 Humidity & temperature Sensor\n\n»);
delay(1000);//Wait before accessing Sensor

}//end «setup()»

void loop(){
//Start of Program

DHT.read11(dht_apin);

Serial.print(«Current humidity = „);
Serial.print(DHT.humidity);
Serial.print(“% „);
Serial.print(“temperature = „);
Serial.print(DHT.temperature);
Serial.println(“C „);

delay(5000);//Wait 5 seconds before accessing sensor again.

//Fastest should be once every two seconds.

}// end loop()


18.05.2020

Реле

Схема подключения:

Скетч:

/*
Blink
Turns on an LED on for one second, then off for one second, repeatedly.

This example code is in the public domain.
*/

// Pin 4 has an LED connected on most Arduino boards.
// give it a name:
int led = 4;

// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}


25.05.2020

Шаговый двигатель 28BYJ-48

Схема подключения:

5V+ connect to +5V
5V- connect to 0V (Ground)
IN1: to Arduino digital input pin 8
IN2: to Arduino digital input pin 9
IN3: to Arduino digital input pin 10
IN4: to Arduino digital input pin 11

Скетч:

// This Arduino example demonstrates bidirectional operation of a
// 28BYJ-48, using a ULN2003 interface board to drive the stepper.
// The 28BYJ-48 motor is a 4-phase, 8-beat motor, geared down by
// a factor of 68. One bipolar winding is on motor pins 1 & 3 and
// the other on motor pins 2 & 4. The step angle is 5.625/64 and the
// operating Frequency is 100pps. Current draw is 92mA.
////////////////////////////////////////////////

//declare variables for the motor pins
int motorPin1 = 8; // Blue — 28BYJ48 pin 1
int motorPin2 = 9; // Pink — 28BYJ48 pin 2
int motorPin3 = 10; // Yellow — 28BYJ48 pin 3
int motorPin4 = 11; // Orange — 28BYJ48 pin 4
// Red — 28BYJ48 pin 5 (VCC)

int motorSpeed = 1200; //variable to set stepper speed
int count = 0; // count of steps made
int countsperrev = 512; // number of steps per full revolution
int lookup[8] = {B01000, B01100, B00100, B00110, B00010, B00011, B00001, B01001};

//////////////////////////////////////////////////////////////////////////////
void setup() {
//declare the motor pins as outputs
pinMode(motorPin1, OUTPUT);
pinMode(motorPin2, OUTPUT);
pinMode(motorPin3, OUTPUT);
pinMode(motorPin4, OUTPUT);
Serial.begin(9600);
}

//////////////////////////////////////////////////////////////////////////////
void loop(){
if(count < countsperrev )
clockwise();
else if (count == countsperrev * 2)
count = 0;
else
anticlockwise();
count++;
}

//////////////////////////////////////////////////////////////////////////////
//set pins to ULN2003 high in sequence from 1 to 4
//delay «motorSpeed» between each pin setting (to determine speed)
void anticlockwise()
{
for(int i = 0; i < 8; i++)
{
setOutput(i);
delayMicroseconds(motorSpeed);
}
}

void clockwise()
{
for(int i = 7; i >= 0; i--)
{
setOutput(i);
delayMicroseconds(motorSpeed);
}
}

void setOutput(int out)
{
digitalWrite(motorPin1, bitRead(lookup[out], 0));
digitalWrite(motorPin2, bitRead(lookup[out], 1));
digitalWrite(motorPin3, bitRead(lookup[out], 2));
digitalWrite(motorPin4, bitRead(lookup[out], 3));
}