TaijaQ
4/15/2017 - 5:32 AM

Raspberry Pi and Arduino development snippets

Raspberry Pi and Arduino development snippets


##
# Turn Any Appliance into a Smart Device with an Arduino Controlled Power Outlet
# http://www.circuitbasics.com/build-an-arduino-controlled-power-outlet/
##

#include <dht.h>

dht DHT;

#define DHT11_PIN 7
int pinOut = 8;

void setup(){
  Serial.begin(9600);
  pinMode(8, OUTPUT);
}

void loop()
{
  int chk = DHT.read11(DHT11_PIN);
  Serial.print("Temperature = ");
  Serial.println(DHT.temperature);
  Serial.print("Humidity = ");
  Serial.println(DHT.humidity);
  if (DHT.humidity <= 40){
    digitalWrite(pinOut, HIGH);
  }
  else {
    digitalWrite(pinOut, LOW);
  }
  delay(500);            
}

NO
LOW = off
#!/usr/bin/python
import sys
import Adafruit_DHT

while True:

    humidity, temperature = Adafruit_DHT.read_retry(11, 4)

    print 'Temp: {0:0.1f} C  Humidity: {1:0.1f} %'.format(temperature, humidity)
###
# How to Set Up A 5V Relay On The Arduino
# http://www.circuitbasics.com/setting-up-a-5v-relay-on-the-arduino/
##


#include <math.h>

int pinOut = 10;

double Thermistor(int RawADC) {
 double Temp;
 Temp = log(10000.0*((1024.0/RawADC-1))); 
 Temp = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * Temp * Temp ))* Temp );
 Temp = Temp - 273.15;          
 Temp = (Temp * 9.0)/ 5.0 + 32.0; 
 return Temp;
}

void setup() {
  Serial.begin(9600);
  pinMode(10, OUTPUT);
}

void loop() {             
  int val;                
  double temp;            
  val=analogRead(0);      
  temp=Thermistor(val);   
  Serial.print("Temperature = ");
  Serial.print(temp);   
  Serial.println(" F");
  if (temp >= 150){
    digitalWrite(pinOut, LOW);
  }
  else {
    digitalWrite(pinOut, HIGH);
  }
  delay(500);            
}
RASPBERRY PI

Mine
  - Piface Digital
  - WiFi Dongle
  - 

Others
  - Adafruit DHT11
  - STM32 F103 C8T6
  - STM32 F030
  - WS2812 Breakout
  - MH-Real-Time Clock Modules -2
  - Mitsumi Stepping Motor (7.5 Step)