Projekt:Tüftlerclub/Arduino
Erscheinungsbild
nRF24L01
[Bearbeiten]Sender
[Bearbeiten]#include <SPI.h>
#include <RF24.h>
RF24 radio(7, 8); // (CE, CSN)
const byte address[6] = "1RF24";
void setup() {
radio.begin();
radio.setPALevel(RF24_PA_MAX);
radio.setChannel(125);
radio.openWritingPipe(address);
radio.stopListening();
}
void loop() {
const char text[] = "Moin";
radio.write(&text, sizeof(text));
delay(2000);
}
Empfänger
[Bearbeiten]#include <SPI.h>
#include <RF24.h>
RF24 radio(7, 8); // (CE, CSN)
const byte address[6] = "1RF24";
void setup() {
Serial.begin(115200);
radio.begin();
radio.setPALevel(RF24_PA_MAX);
radio.setChannel(125);
radio.openReadingPipe(0,address);
radio.startListening();
}
void loop() {
if(radio.available()){
char text[33] = {0};
radio.read(&text, sizeof(text)-1);
Serial.println(text);
}
}
RFID
[Bearbeiten]DumpToSerial
[Bearbeiten]#include <SPI.h>
#include <MFRC522.h>
const int resetPIN = 9;
const int slavePIN = 10;
MFRC522 mfrc522(slavePIN, resetPIN);
void setup() {
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
}
void loop() {
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
}
UID
[Bearbeiten]#include <SPI.h>
#include <MFRC522.h>
const int resetPIN = 9;
const int slavePIN = 10;
MFRC522 mfrc522(slavePIN, resetPIN);
void setup() {
Serial.begin(9600);
SPI.begin();
mfrc522.PCD_Init();
}
void loop() {
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
Serial.print("ID:");
for (int i = 0; i < mfrc522.uid.size; i++) {
Serial.print(mfrc522.uid.uidByte[i], HEX);
Serial.print(" ");
}
Serial.println();
}
Bluetooth
[Bearbeiten]Module
[Bearbeiten]Typ: DSD TECH HM-11 Bluetooth 4.0 BLE-Modul
AT-Befehlssatz:
- AT+IMME1 -> start work after AT+START, AT+CON, AT+CONNL commands
- AT+ROLE1 -> master / central role
- AT+DISC? -> discovery scan
- AT+CON6C79B8B6DF44 -> connect an device with MAC address
1
[Bearbeiten]- A5DFF72A-D084-473F-BO35-637025B24A85
- MAC: 6C79B8B6DF44
2
[Bearbeiten]- A9BF45E6-7D70-4A9B-8A9B-0A213E7393D7
- MAC: 6C79B8B48559
Master
[Bearbeiten]#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); // RX, TX
void setup() {
BTSerial.begin(9600);
BTSerial.print("AT");
BTSerial.print("AT+IMME1");
BTSerial.print("AT+ROLE1");
BTSerial.print("AT+DISC?");
delay(800);
BTSerial.print("AT+CON6C79B8B6DF44");
delay(800);
}
void loop() {
BTSerial.print("Test");
delay(1000);
}
Slave
[Bearbeiten]#include <SoftwareSerial.h>
SoftwareSerial BTSerial(10, 11); // RX, TX
void setup() {
Serial.begin(9600);
delay(500);
BTSerial.begin(9600);
}
void loop() {
if (BTSerial.available())
Serial.write(BTSerial.read());
}
IR-Empfang
[Bearbeiten]#include <IRremote.h>
int IrWert = 0;
const int IrPin = 10;
void setup() {
IrReceiver.begin(IrPin);
Serial.begin(9600);
}
void loop() {
if (IrReceiver.decode()) {
IrReceiver.resume();
IrWert = IrReceiver.decodedIRData.command;
Serial.print(IrWert);
delay(500);
}
}
Servomotor
[Bearbeiten]#include <Servo.h>
Servo myservoA;
Servo myservoB;
void setup() {
myservoA.attach(9);
myservoB.attach(10);
}
void servo(char servo, int pos, int msek) {
if (servo == 'A') {
myservoA.write(pos);
delay(msek);
}
if (servo == 'B') {
myservoB.write(pos);
delay(msek);
}
if (servo == 'X') {
myservoA.write(pos);
myservoB.write(pos);
delay(msek);
}}
void loop() {
servo('X',0,1000);
servo('X',180,1000);
}
Farbmischer
[Bearbeiten]const int rSensor = A1;
const int gSensor = A2;
const int bSensor = A3;
const int rPin = 9;
const int gPin = 10;
const int bPin = 11;
int rValue = 0;
int gValue = 0;
int bValue = 0;
void setup() {
pinMode(rPin, OUTPUT);
pinMode(gPin, OUTPUT);
pinMode(bPin, OUTPUT);
}
void loop() {
rValue = analogRead(rSensor);
gValue = analogRead(gSensor);
bValue = analogRead(bSensor);
rValue = 255 - (rValue / 4);
gValue = 255 - (gValue / 4);
bValue = 255 - (bValue / 4);
analogWrite(rPin,rValue);
analogWrite(gPin,gValue);
analogWrite(bPin,bValue);
delay(100);
}